// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace SnapObjects.Data
{
    /// <summary>
    ///     The base interface of ISqlBuilder and ISqlReadOnlyBuilder.
    /// </summary>
    public interface ISqlBuilderBase
    {
        /// <summary>
        ///     Gets the name of the current object.
        /// </summary>
        string Name { get; }

        /// <summary>
        ///     Gets the SQL statement type of the current object.
        /// </summary>
        SqlStatementType SqlType { get; }

        /// <summary>
        ///     Gets an IReadOnlyDictionary<string, ISqlParameter> object that contains all parameters used in the current object.
        /// </summary>
        IReadOnlyDictionary<string, ISqlParameter> UsedParameters { get; }

        /// <summary>
        ///     Returns the raw SQL string for the corresponding database by the current object.
        /// </summary>
        /// <param name="context">
        ///     A DataContext object which contains the database connection information.
        /// </param>
        /// <returns>Returns the raw SQL string.</returns>
        string ToSqlString(DataContext context);

        /// <summary>
        ///     Validates the raw SQL string for the specified database generated by the current sqlbuilder.
        /// </summary>
        /// <param name="context">A DataContext object which contains the database connection information.</param>
        /// <param name="throwError">
        ///     True (default ) -- to throw an exception if the raw SQL is not valid in the specified database;
        ///     False -- Not to throw an exception if the raw SQL is not valid in the specified database.
        /// </param>
        /// <returns>
        ///     Returns true if the raw SQL is valid in the specified database; false if the raw SQL is not valid in the specified database.
        /// </returns>
        bool Validate(DataContext context, bool throwError = true);

        Task<bool> ValidateAsync(DataContext context, bool throwError = true);

        Task<bool> ValidateAsync(DataContext context, bool throwError, CancellationToken cancellationToken = default);
    }
}
